package com.cmc.cloud.cmclink.doc.api.document;

import com.cmc.cloud.cmclink.doc.api.document.req.PortSpecialRequestDto;
import com.cmc.cloud.cmclink.doc.convert.PortSpecialRequestConvert;
import com.cmc.cloud.cmclink.doc.entity.PortSpecialRequestDO;
import com.cmc.cloud.cmclink.doc.mapper.PortSpecialRequestMapper;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
/**
 * @author lcp
 * @date 2025/7/7
 */
@RestController
public class PortSpecialRequestApiImpl implements PortSpecialRequestApi {

    @Resource
    private PortSpecialRequestMapper portSpecialRequestMapper;

    @Override
    public CommonResult<List<PortSpecialRequestDto>> queryPortSpecialRequestInfo(String portCode, String portType) {
        LambdaQueryWrapperX<PortSpecialRequestDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        lambdaQueryWrapperX.eq(PortSpecialRequestDO::getPortCode, portCode)
                .eq(PortSpecialRequestDO::getPortType, portType);
        List<PortSpecialRequestDO> portSpecialRequestDoList = portSpecialRequestMapper.selectList(lambdaQueryWrapperX);
        if (CollectionUtils.isEmpty(portSpecialRequestDoList)) {
            return CommonResult.success(Collections.emptyList());
        }
        return CommonResult.success(PortSpecialRequestConvert.INSTANCE.convert(portSpecialRequestDoList));
    }
}
